package com.nine.system.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.nine.common.entity.User;
import com.nine.common.tool.ResponseResult;
import com.nine.system.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @ClassName: LoginController
 * @Author: luodeng
 * @Date: 2023/6/7 18:40
 * @Version: 1.0
 */
@RestController
@Api(tags = "登录api",description = "登录注销相关的api")
public class LoginController {

    @Autowired
    private LoginService service;

    @ApiOperation(value = "登录接口")
    @ApiImplicitParam(value = "账号密码类",name = "user",dataType = "User",dataTypeClass = User.class,paramType = "body")
    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user){
        return service.login(user);
    }

    @ApiOperation(value = "注销接口")
    @GetMapping("/logout")
    public ResponseResult logout(){
        return service.logout();
    }

    @ApiOperation(value = "通过手机号发送验证码")
    @ApiImplicitParam(value = "手机号",name = "phoneNumber",dataType = "String",dataTypeClass = String.class,paramType = "path")
    @GetMapping("/resetPassword/{phoneNumber}")
    public ResponseResult reset(@PathVariable String phoneNumber){

        return service.resetPassword(phoneNumber);
    }

    @ApiOperation(value = "校验信息后进行重置密码操作")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号",name = "phoneNumber",dataType = "String",dataTypeClass = String.class,paramType = "query"),
            @ApiImplicitParam(value = "验证码",name = "code",dataType = "String",dataTypeClass = String.class,paramType = "query"),
            @ApiImplicitParam(value = "新密码",name = "newPassword",dataType = "String",dataTypeClass = String.class,paramType = "query"),
    })
    @PostMapping("/doVerify")
    public ResponseResult doVerify(@RequestParam("phoneNumber")String phoneNumber,
                                   @RequestParam("code")String code,
                                   @RequestParam("newPassword")String newPassword){
        return service.doVerify(phoneNumber,code,newPassword);
    }

}
